home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.2 / Libraries / DOS / readargs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  2.6 KB  |  101 lines

  1. /*
  2.  * Copyright (C) 1990 Commodore-Amiga, Inc.
  3.  * All rights reserved
  4.  */
  5.  
  6.  
  7. /* This is an example of the command-line processing for a print program */
  8. /* Compiled with Lattice C 5.05: lc -cfist -v -L readargs.c */
  9.  
  10. #include <exec/types.h>
  11. #include <dos/dos.h>
  12. #include <dos/rdargs.h>
  13. #include <clib/dos_protos.h>
  14.  
  15. /* normally you'ld include pragmas here */
  16.  
  17. #define TEMPLATE          "Files/M/A,Header/K,Spool/S,Page=PageNumber/K/N"
  18. #define OPT_FILES         0
  19. #define OPT_HEADER        1
  20. #define OPT_SPOOL         2
  21. #define OPT_PAGE          3
  22. #define OPT_COUNT         4
  23.  
  24. LONG opts[OPT_COUNT];        /* C guarantees this will be all 0's! */
  25.  
  26. int main (int, char **);
  27.  
  28. int
  29. main (argc,argv)
  30.     int argc;
  31.     char **argv;
  32. {
  33.     struct RDArgs *argsptr;
  34.     char **sptr;
  35.  
  36.  
  37.       /*==================================================================*/
  38.       /* If ReadArgs() sees anything but zeros passed to it in elements   */
  39.       /* of this array, ReadArgs() will assume that they are defaults.    */
  40.       /*==================================================================*/
  41.       argsptr = ReadArgs(TEMPLATE, opts, NULL);
  42.  
  43.       /*=================================================================*/
  44.       /* argsptr will be NULL if ReadArgs() failed, the secondary result */
  45.       /* code is fetched by IoErr().                                     */
  46.       /*=================================================================*/
  47.       if (argsptr == NULL)
  48.       {
  49.         PrintFault(IoErr(), NULL);    /* prints the appropriate err message */
  50.     return RETURN_ERROR;
  51.       }
  52.       else
  53.       {
  54.     sptr = (char **) (opts[OPT_FILES]);
  55.         if (!sptr)
  56.         /* this can never actually happen, due to /A */
  57.         VPrintf("No files specified!\n",NULL);
  58.     else {
  59.         VPrintf("files specified:\n",NULL);
  60.  
  61.         /* last string ptr is NULL */
  62.         while (*sptr)
  63.         {
  64.             /* VPrintf takes a ptr to an array of arguments! */
  65.             VPrintf("\t%s\n",(LONG *) sptr);
  66.             sptr++;
  67.         }
  68.     }
  69.  
  70.     /* if option was not specified, it will be NULL (since buffer started */
  71.     /* with opt[] array all NULL).                          */
  72.  
  73.     if (opts[OPT_HEADER])
  74.     {
  75.         /* remember, opts[OPT_HEADER] has a string ptr, and */
  76.         /* VPrintf wants a pointer to that pointer.         */
  77.         VPrintf("Header is '%s'\n",&(opts[OPT_HEADER]));
  78.     }
  79.  
  80.     if (opts[OPT_SPOOL])
  81.     {
  82.         VPrintf("Spooling selected\n",NULL);
  83.     }
  84.  
  85.     if (opts[OPT_PAGE])
  86.     {
  87.         /* the actual number can be accessed by
  88.             *((LONG *) opts[OPT_PAGE])
  89.         */
  90.         VPrintf("Asked to print page %ld\n",(LONG *) (opts[OPT_PAGE]));
  91.     }
  92.  
  93.     /* normally the meat of the program would go here */
  94.  
  95.     /* cleanup */
  96.     FreeArgs(argsptr);
  97.       }
  98.  
  99.       return RETURN_OK;        /* program succeeded */
  100. }
  101.